package com.ylxn.chapter01;

/**
 * 打断正常运行的线程
 */
public class demo05 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (true){
                System.out.println(Thread.currentThread().getName()+"is running");
                if (Thread.currentThread().isInterrupted()){
                    System.out.println("线程被打断");
                    break;
                }
            }
        }, "thread -01");
        thread.start();
        Thread.sleep(1000);
        thread.interrupt();

    }
}
